﻿/* Filename: CaesarCipher.cs
 * Author: Vo Manh Cuong
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;

namespace VMCCryptoLib.SubstitutionCipher
{
    /// <summary>
    /// A Caesar cipher shifts letters in a string. 
    /// In this cipher, each letter is shifted a certain number of places in the alphabet. 
    /// If the letter overflows, it begins again at the letter 'a'.
    /// 
    /// In the Caesar method, we convert the string to a char array with ToCharArray. 
    /// Next, we apply the shift value to every character. 
    /// If the character goes above 'z', we shift it back 26 places.
    /// If the character goes below 'a', we shift it forward 26 places. 
    /// This is correct for all lowercase letters.
    /// </summary>
    class CaesarCipher
    {
        public static string ThisString(string input, int shift)
        {
            char[] result = input.ToCharArray();

            for(int i=0; i<result.Length; i++)
            {
                char letter = result[i];
                letter = (char)(letter + shift);

                if (letter > 'z')
                {
                    letter = (char)(letter - 26);
                }
                else if (letter < 'z')
                {
                    letter = (char)(letter + 26);
                }
                result[i] = letter;
            }

            return new string(result);
        }
    }
}
